package leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

public class Lc17_2 {
    List<String> ans;
    HashMap<Character, char[]> map;

    public List<String> letterCombinations(String digits) {
        ans = new ArrayList<>();
        if (digits == null || digits.length() == 0)
            return ans;
        map = new HashMap<>();
        map.put('2', new char[]{'a', 'b', 'c'});
        map.put('3', new char[]{'d', 'e', 'f'});
        map.put('4', new char[]{'g', 'h', 'i'});
        map.put('5', new char[]{'j', 'k', 'l'});
        map.put('6', new char[]{'m', 'n', 'o'});
        map.put('7', new char[]{'p', 'q', 'r', 's'});
        map.put('8', new char[]{'t', 'u', 'v'});
        map.put('9', new char[]{'w', 'x', 'y', 'z'});
        getAns(digits, 0, "");
        return ans;
    }

    public void getAns(String digits, int idx, String seq) {
        if (idx == digits.length()) {
            ans.add(seq);
            return;
        }
        char[] chars = map.get(digits.charAt(idx));
        for (int i = 0; i < chars.length; i++) {
            getAns(digits, idx + 1, seq + chars[i]);
        }
    }
}
